package com.itc.bpm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itc.bpm.bean.BpmAbnormalReporting;
import com.itc.bpm.bean.BpmFormDesign;
import com.itc.bpm.bean.BpmModel;
import com.itc.bpm.bean.BpmProcessCommunicate;
import com.itc.bpm.service.BpmAbnormalReportingService;
import com.itc.common.core.domain.R;
import com.itc.common.core.utils.StringUtils;
import com.itc.common.core.validate.Add;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "异常上报")
@RestController
@RequestMapping("/bpm/abnormalReporting")
public class BpmAbnormalReportingController {

    @Autowired
    BpmAbnormalReportingService bpmAbnormalReportingService;
    @ApiOperation(value = "新增 异常上报记录")
    @PostMapping("/add")
    public R addForm(@Validated(Add.class) @RequestBody BpmAbnormalReporting bpmAbnormalReporting){
        bpmAbnormalReporting.setDelFlag(0);
        bpmAbnormalReportingService.save(bpmAbnormalReporting);
        return R.ok();
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询异常沟通记录")
    public R<List<BpmAbnormalReporting>> getList(@RequestBody BpmAbnormalReporting reporting)
    {
        if(StringUtils.isEmpty(reporting.getProcessInstanceId())){
            return R.fail("流程实例id不能为空");
        }
        reporting.setDelFlag(0);
        LambdaQueryWrapper<BpmAbnormalReporting> queryWrapper = new LambdaQueryWrapper<>(reporting).orderByAsc(BpmAbnormalReporting::getCreateTime);
        List<BpmAbnormalReporting> list = bpmAbnormalReportingService.list(queryWrapper);
        return R.ok(list);
    }
}
